package com.jian.bus.service.impl;

import com.jian.bus.pojo.Goods;
import com.jian.bus.pojo.Inport;
import com.jian.bus.pojo.Outport;
import com.jian.bus.mapper.OutportMapper;
import com.jian.bus.service.GoodsService;
import com.jian.bus.service.InportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jian.bus.service.OutportService;
import com.jian.sys.common.WebUtils;
import com.jian.sys.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 剑
 * @since 2020-01-23
 */
@Service
@Transactional
public class OutportServiceImpl extends ServiceImpl<OutportMapper, Outport> implements OutportService {
    @Autowired
    GoodsService goodsService;
    @Autowired
    InportService inportService;
    @Override
    public void saveOutportInfo(Integer id, String remark, Integer number) {
        Inport inport = this.inportService.getById(id);
        Goods goods = this.goodsService.getById(inport.getGoodsid());
        //退货 减除对应的退货数量
        goods.setNumber(goods.getNumber()-number);
        goodsService.updateById(goods);

        Outport outport = new Outport();
        outport.setNumber(number);
        outport.setRemark(remark);
        outport.setOutporttime(new Date());
        outport.setPaytype(inport.getPaytype());
        outport.setGoodsid(inport.getGoodsid());
        outport.setProviderid(inport.getProviderid());
        User user=(User) WebUtils.getSession().getAttribute("user");
        outport.setOperateperson(user.getName());
        outport.setOutportprice(inport.getInportprice());
        this.baseMapper.insert(outport);
    }
}
